<?php
/* 
* [登录控制器]
* @author: mazhenyu[houdunwangmzy@163.com]
* @Date:   2014-06-16 14:01:05
* @Last Modified time: 2014-06-20 13:43:42
*/
class LoginControl extends Control{
	/**
	 * [index 显示登录页面]
	 * @return [type] [description]
	 */
	public function index(){
		if(IS_POST){
			$userModel = K('User');
			//执行模型里面的验证，返回布尔值或者用户数据
			$userData = $userModel->validate_login('admin');
			//如果为假则是验证没有通过
			if(!$userData) $this->error($userModel->error,U('index'),5);
			//存入session信息
			session('aid',$userData['uid']);
			session('adminname',$userData['username']);
			//提示登录成功
			
			$this->success('登录成功',U('Index/index'));
		}
		//检测是否登录，如果登录则跳转到后台首页
		if(isset($_SESSION['aid']) && isset($_SESSION['adminname'])){
			go(U('Index/index'));
		}
		$this->display();
	}

	/**
	 * [code 显示验证码]
	 * @return [type] [description]
	 */
	public function code(){
		$code = new Code();
		$code->show();
	}

	/**
	 * [out 退出登录]
	 * @return [type] [description]
	 */
	public function out(){
		session('aid',NULL);
		session('adminname',NULL);
		$this->success('退出成功');
	}

}

